package com.baidu.io;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class D06_FileReaderCopy {
    public static void main(String[] args) {

        //1.创建字节输入流
        FileReader fileReader = null;
        //2.创建字节输出流
        FileWriter fileWriter = null;

        try {
            //1.创建字节输入流
            fileReader = new FileReader("src/002.dat");

            //2.创建字节输出流
            fileWriter = new FileWriter("src/002_copy_dat");

            //3.创建单次获取字节数组
            char[] chars = new char[32];

            //4.创建获取长度用于最后一桶的及写出的指针
            int len = -1;

            //5.循环读取数据并写入
            while ((len = fileReader.read(chars)) != -1){
                fileWriter.write(chars, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(null != fileReader) fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if(null != fileWriter) fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
